package com.code.origin.utils.collection;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeansException;

import java.util.ArrayList;
import java.util.List;

public class ListUtils {

	public static <T> List<T> adds(T... t) {
		List<T> list = new ArrayList<>();
		for (int i = 0; i < t.length; i++) {
			list.add(t[i]);
		}
		
		return list;
	}
	
	public static boolean isEmpty(List<?> list) {
		if (list == null || list.isEmpty()) {
			return true;
		} else {
			return false;
		}
	}
	
	public static boolean isNotEmpty(List<?> list) {
		
		return !isEmpty(list);
	}
	
	/**
	 * 批量复制并转换list
	 * @param sourceList 
	 * @param targetClass  目标类
	 * @return
	 */
	public static <E>List<E> copyList (List< ? extends Object> sourceList , Class<E> targetClass){
        
        List<E> targetList = new ArrayList<E>();
         
        E targetObj =null;
        for(Object sourceObj : sourceList){
            try {
            	if(sourceObj != null) {
            		targetObj = targetClass.newInstance();
                    BeanUtils.copyProperties(sourceObj, targetObj);
            	}
            } catch (InstantiationException | IllegalAccessException | BeansException e) {
                e.printStackTrace();
            }
            targetList.add(targetObj);
        }
        return targetList;
         
    }
}
